import {create, all} from 'mathjs'

const config: any = {
    number: 'BigNumber',
    precision: 20
}
const math = create(all, config);
export default {
    //开方
    // numberSqrt: function(arg1){
    //     return math math.sqrt(arg1)
    // },
    //除
    divide: function (arg1: any, arg2: any) {
        return math.divide(arg1, arg2);
    },
    //乘
    multiply: function (arg1: any, arg2: any) {
        return math.multiply(arg1, arg2);
    },
    //加
    add: function (arg1: any, arg2: any) {
        return math.add(arg1, arg2);
    },
    //减
    subtract: function (arg1: any, arg2: any) {
        return math.subtract(arg1, arg2);
    },


    // 小数处理
    setDecimal(value: any, precision?: number) {
        precision = precision || 2
        return value ? (isNaN(Number(value)) || value === -Infinity || value === Infinity) ? 0 : Number(Number(value).toFixed(precision)) : 0
    },

    // 整数处理
    setInt(value: any) {
        return isNaN(Number(value)) ? 0 : Number(value)
    },

}
